#include "global.h"
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<ctime>
using namespace std;

void getQA(int no,std::string *question,double *answer,double *WA1,double *WA2,double *WA3)
{
    int j,i;
    int a,b,y,z,m,n,t;
    char c[10];
    for(i=0;i<10;i++)
    {
        if(no==1){
            j=rand()%2;
            switch(j)
            {
            case 0://加法
                {
                a=1+rand()%9;
                b=1+rand()%9;

                    c[0]='0'+a;
                    c[1]='+';
                    c[2]='0'+b;
                    c[3]='=';
                    c[4]='\0';

                *question = c;
                *answer=a+b;
                *WA1=1+rand()%9;
                *WA2=1+rand()%20;
                *WA3=1+rand()%9;
                break;
                }
            case 1://减法
                {
                a=1+rand()%9;
                b=1+rand()%9;
                if(a<b) {
                    t=a;
                    a=b;
                    b=t;
                }

                        c[0]='0'+a;
                        c[1]='-';
                        c[2]='0'+b;
                        c[3]='=';
                        c[4]='\0';

                *question = c;
                *answer=a-b;
                *WA1=1+rand()%9;
                *WA2=1+rand()%9;
                *WA3=1+rand()%9;
                break;
                    }
        }
        }
        if(no==2){
             j=rand()%3;
            switch(j)
            {
            case 0://加法
                {
                a=1+rand()%50;
                b=1+rand()%50;
                if(a>=10&&b>=10){
                    z=a%10;
                    y=a/10;
                    c[0]='0'+y;
                    c[1]='0'+z;
                    m=b%10;
                    n=b/10;
                    c[2]='+';
                    c[3]='0'+n;
                    c[4]='0'+m;
                    c[5]='=';
                    c[6]='\0';
                }
                else if(a>=10&&b<=10)
                {
                    z=a%10;
                    y=a/10;
                    c[0]='0'+y;
                    c[1]='0'+z;
                    c[2]='+';
                    c[3]='0'+b;
                    c[4]='=';
                    c[5]='\0';
                }
                else if(a<=10&&b>=10){
                    c[0]='0'+a;
                    m=b%10;
                    n=b/10;
                    c[1]='+';
                    c[2]='0'+n;
                    c[3]='0'+m;
                    c[4]='=';
                    c[5]='\0';
                }
                else{
                    c[0]='0'+a;
                    c[1]='+';
                    c[2]='0'+b;
                    c[3]='=';
                    c[4]='\0';
                }
                *question = c;
                *answer=a+b;
                *WA1=1+rand()%100;
                *WA2=1+rand()%100;
                *WA3=1+rand()%100;
                break;
                }
            case 1://减法
                {
                a=1+rand()%50;
                b=1+rand()%50;
                if(a<b) {
                    t=a;
                    a=b;
                    b=t;
                }
                    if(a>=10&&b>=10){
                        z=a%10;
                        y=a/10;
                        c[0]='0'+y;
                        c[1]='0'+z;
                        m=b%10;
                        n=b/10;
                        c[2]='-';
                        c[3]='0'+n;
                        c[4]='0'+m;
                        c[5]='=';
                        c[6]='\0';
                    }
                    else if(a>=10&&b<=10)
                    {
                        z=a%10;
                        y=a/10;
                        c[0]='0'+y;
                        c[1]='0'+z;
                        c[2]='-';
                        c[3]='0'+b;
                        c[4]='=';
                        c[5]='\0';
                    }
                    else if(a<=10&&b>=10){
                        c[0]='0'+a;
                        m=b%10;
                        n=b/10;
                        c[1]='-';
                        c[2]='0'+n;
                        c[3]='0'+m;
                        c[4]='=';
                        c[5]='\0';
                    }
                    else{
                        c[0]='0'+a;
                        c[1]='-';
                        c[2]='0'+b;
                        c[3]='=';
                        c[4]='\0';
                    }
                *question = c;
                *answer=a-b;
                *WA1=1+rand()%50;
                *WA2=1+rand()%20;
                *WA3=1+rand()%50;
                break;
                    }
            case 2://乘法
                {
                a=1+rand()%9;
                b=1+rand()%9;
                if(a>=b&&a%b==0)
                {


                        c[0]='0'+a;
                        c[1]='*';
                        c[2]='0'+b;
                        c[3]='=';
                        c[4]='\0';

                    *question = c;
                    *answer=a*b;
                    *WA1=1+rand()%100;
                    *WA2=1+rand()%100;
                    *WA3=1+rand()%100;
                }
                break;
                }
            }
        }

        if(no==5){
            j=rand()%4;
            switch(j)
            {
            case 0://加法
                {
                a=1+rand()%100;
                b=1+rand()%100;
                if(a>=10&&b>=10){
                    z=a%10;
                    y=a/10;
                    c[0]='0'+y;
                    c[1]='0'+z;
                    m=b%10;
                    n=b/10;
                    c[2]='+';
                    c[3]='0'+n;
                    c[4]='0'+m;
                    c[5]='=';
                    c[6]='\0';
                }
                else if(a>=10&&b<=10)
                {
                    z=a%10;
                    y=a/10;
                    c[0]='0'+y;
                    c[1]='0'+z;
                    c[2]='+';
                    c[3]='0'+b;
                    c[4]='=';
                    c[5]='\0';
                }
                else if(a<=10&&b>=10){
                    c[0]='0'+a;
                    m=b%10;
                    n=b/10;
                    c[1]='+';
                    c[2]='0'+n;
                    c[3]='0'+m;
                    c[4]='=';
                    c[5]='\0';
                }
                else{
                    c[0]='0'+a;
                    c[1]='+';
                    c[2]='0'+b;
                    c[3]='=';
                    c[4]='\0';
                }
                *question = c;
                *answer=a+b;
                *WA1=1+rand()%100;
                *WA2=1+rand()%100;
                *WA3=1+rand()%100;
                break;
                }
            case 1://减法
                {
                a=1+rand()%100;
                b=1+rand()%100;
                    if(a>=10&&b>=10){
                        z=a%10;
                        y=a/10;
                        c[0]='0'+y;
                        c[1]='0'+z;
                        m=b%10;
                        n=b/10;
                        c[2]='-';
                        c[3]='0'+n;
                        c[4]='0'+m;
                        c[5]='=';
                        c[6]='\0';
                    }
                    else if(a>=10&&b<=10)
                    {
                        z=a%10;
                        y=a/10;
                        c[0]='0'+y;
                        c[1]='0'+z;
                        c[2]='-';
                        c[3]='0'+b;
                        c[4]='=';
                        c[5]='\0';
                    }
                    else if(a<=10&&b>=10){
                        c[0]='0'+a;
                        m=b%10;
                        n=b/10;
                        c[1]='-';
                        c[2]='0'+n;
                        c[3]='0'+m;
                        c[4]='=';
                        c[5]='\0';
                    }
                    else{
                        c[0]='0'+a;
                        c[1]='-';
                        c[2]='0'+b;
                        c[3]='=';
                        c[4]='\0';
                    }
                *question = c;
                *answer=a-b;
                *WA1=1+rand()%100;
                *WA2=1+rand()%100;
                *WA3=1-rand()%100;
                break;
                    }
            case 2://乘法
                {
                a=1+rand()%9;
                b=1+rand()%20;
                if(a>=b&&a%b==0)
                {
                    if(a>=10&&b>=10){
                        z=a%10;
                        y=a/10;
                        c[0]='0'+y;
                        c[1]='0'+z;
                        m=b%10;
                        n=b/10;
                        c[2]='*';
                        c[3]='0'+n;
                        c[4]='0'+m;
                        c[5]='=';
                        c[6]='\0';
                    }
                    else if(a>=10&&b<=10)
                    {
                        z=a%10;
                        y=a/10;
                        c[0]='0'+y;
                        c[1]='0'+z;
                        c[2]='*';
                        c[3]='0'+b;
                        c[4]='=';
                        c[5]='\0';
                    }
                    else if(a<=10&&b>=10){
                        c[0]='0'+a;
                        m=b%10;
                        n=b/10;
                        c[1]='*';
                        c[2]='0'+n;
                        c[3]='0'+m;
                        c[4]='=';
                        c[5]='\0';
                    }
                    else{
                        c[0]='0'+a;
                        c[1]='*';
                        c[2]='0'+b;
                        c[3]='=';
                        c[4]='\0';
                    }
                    *question = c;
                    *answer=a*b;
                    *WA1=1+rand()%100;
                    *WA2=1+rand()%100;
                    *WA3=1+rand()%100;
                }
                break;
                }
            case 3:
            {
                t=1+rand()%9;
                b=1+rand()%9;
                a=b*t;
                if(a>=b&&a%b==0)
                {
                    if(a>=10&&b>=10){
                        z=a%10;
                        y=a/10;
                        c[0]='0'+y;
                        c[1]='0'+z;
                        m=b%10;
                        n=b/10;
                        c[2]='/';
                        c[3]='0'+n;
                        c[4]='0'+m;
                        c[5]='=';
                        c[6]='\0';
                    }
                    else if(a>=10&&b<=10)
                    {
                        z=a%10;
                        y=a/10;
                        c[0]='0'+y;
                        c[1]='0'+z;
                        c[2]='/';
                        c[3]='0'+b;
                        c[4]='=';
                        c[5]='\0';
                    }
                    else if(a<=10&&b>=10){
                        c[0]='0'+a;
                        m=b%10;
                        n=b/10;
                        c[1]='/';
                        c[2]='0'+n;
                        c[3]='0'+m;
                        c[4]='=';
                        c[5]='\0';
                    }
                    else{
                        c[0]='0'+a;
                        c[1]='/';
                        c[2]='0'+b;
                        c[3]='=';
                        c[4]='\0';
                    }
                    *question = c;
                    *answer=t;
                    *WA1=1+rand()%100;
                    *WA2=1+rand()%100;
                    *WA3=1+rand()%9;
                }
                break;
            }
        }
        }


        if(no==3||no==4){
        j=rand()%4;
        switch(j)
        {
        case 0://加法
            {
            a=1+rand()%100;
            b=1+rand()%100;
            if(a>=10&&b>=10){
                z=a%10;
                y=a/10;
                c[0]='0'+y;
                c[1]='0'+z;
                m=b%10;
                n=b/10;
                c[2]='+';
                c[3]='0'+n;
                c[4]='0'+m;
                c[5]='=';
                c[6]='\0';
            }
            else if(a>=10&&b<=10)
            {
                z=a%10;
                y=a/10;
                c[0]='0'+y;
                c[1]='0'+z;
                c[2]='+';
                c[3]='0'+b;
                c[4]='=';
                c[5]='\0';
            }
            else if(a<=10&&b>=10){
                c[0]='0'+a;
                m=b%10;
                n=b/10;
                c[1]='+';
                c[2]='0'+n;
                c[3]='0'+m;
                c[4]='=';
                c[5]='\0';
            }
            else{
                c[0]='0'+a;
                c[1]='+';
                c[2]='0'+b;
                c[3]='=';
                c[4]='\0';
            }
            *question = c;
            *answer=a+b;
            *WA1=1+rand()%100;
            *WA2=1+rand()%100;
            *WA3=1+rand()%100;
            break;
            }
        case 1://减法
            {
            a=1+rand()%100;
            b=1+rand()%100;
            if(a<b) {
                t=a;
                a=b;
                b=t;
            }
                if(a>=10&&b>=10){
                    z=a%10;
                    y=a/10;
                    c[0]='0'+y;
                    c[1]='0'+z;
                    m=b%10;
                    n=b/10;
                    c[2]='-';
                    c[3]='0'+n;
                    c[4]='0'+m;
                    c[5]='=';
                    c[6]='\0';
                }
                else if(a>=10&&b<=10)
                {
                    z=a%10;
                    y=a/10;
                    c[0]='0'+y;
                    c[1]='0'+z;
                    c[2]='-';
                    c[3]='0'+b;
                    c[4]='=';
                    c[5]='\0';
                }
                else if(a<=10&&b>=10){
                    c[0]='0'+a;
                    m=b%10;
                    n=b/10;
                    c[1]='-';
                    c[2]='0'+n;
                    c[3]='0'+m;
                    c[4]='=';
                    c[5]='\0';
                }
                else{
                    c[0]='0'+a;
                    c[1]='-';
                    c[2]='0'+b;
                    c[3]='=';
                    c[4]='\0';
                }
            *question = c;
            *answer=a-b;
            *WA1=1+rand()%100;
            *WA2=1+rand()%100;
            *WA3=1+rand()%100;
            break;
                }
        case 2://乘法
            {
            a=1+rand()%9;
            b=1+rand()%20;
            if(a>=b&&a%b==0)
            {
                if(a>=10&&b>=10){
                    z=a%10;
                    y=a/10;
                    c[0]='0'+y;
                    c[1]='0'+z;
                    m=b%10;
                    n=b/10;
                    c[2]='*';
                    c[3]='0'+n;
                    c[4]='0'+m;
                    c[5]='=';
                    c[6]='\0';
                }
                else if(a>=10&&b<=10)
                {
                    z=a%10;
                    y=a/10;
                    c[0]='0'+y;
                    c[1]='0'+z;
                    c[2]='*';
                    c[3]='0'+b;
                    c[4]='=';
                    c[5]='\0';
                }
                else if(a<=10&&b>=10){
                    c[0]='0'+a;
                    m=b%10;
                    n=b/10;
                    c[1]='*';
                    c[2]='0'+n;
                    c[3]='0'+m;
                    c[4]='=';
                    c[5]='\0';
                }
                else{
                    c[0]='0'+a;
                    c[1]='*';
                    c[2]='0'+b;
                    c[3]='=';
                    c[4]='\0';
                }
                *question = c;
                *answer=a*b;
                *WA1=1+rand()%100;
                *WA2=1+rand()%100;
                *WA3=1+rand()%100;
            }
            break;
            }
        case 3:
        {
            t=1+rand()%9;
            b=1+rand()%9;
            a=b*t;
            if(a>=b&&a%b==0)
            {
                if(a>=10&&b>=10){
                    z=a%10;
                    y=a/10;
                    c[0]='0'+y;
                    c[1]='0'+z;
                    m=b%10;
                    n=b/10;
                    c[2]='/';
                    c[3]='0'+n;
                    c[4]='0'+m;
                    c[5]='=';
                    c[6]='\0';
                }
                else if(a>=10&&b<=10)
                {
                    z=a%10;
                    y=a/10;
                    c[0]='0'+y;
                    c[1]='0'+z;
                    c[2]='/';
                    c[3]='0'+b;
                    c[4]='=';
                    c[5]='\0';
                }
                else if(a<=10&&b>=10){
                    c[0]='0'+a;
                    m=b%10;
                    n=b/10;
                    c[1]='/';
                    c[2]='0'+n;
                    c[3]='0'+m;
                    c[4]='=';
                    c[5]='\0';
                }
                else{
                    c[0]='0'+a;
                    c[1]='/';
                    c[2]='0'+b;
                    c[3]='=';
                    c[4]='\0';
                }
                *question = c;
                *answer=t;
                *WA1=1+rand()%100;
                *WA2=1+rand()%100;
                *WA3=1+rand()%9;
            }
            break;
        }
        }
        }
    }
}


